const express = require('express');
const app = express();
const flash = require('connect-flash');
const morgan = require('morgan');

const session = require('./middleware/session')
const route = require('./routes');
const credentials = require('./middleware/credentials');
const response = require('./middleware/response');
const parse = require('./middleware/parse');
const exception = require('./middleware/exception');
const intercept = require('./middleware/intercept');
var path = require('path');



// log every request to the console
app.use(morgan('dev'));
// use connect-flash for flash messages stored in session
app.use(flash());
//global response
response(app)
//cross domain
credentials(app)

//parse form
parse(app,express)

session(app)
//global log
intercept(app)



//auto route
route(app)

//handle exception
exception(app)


app.use(express.static(path.join(__dirname, '../public')));

module.exports = app
